<%--
  Created by IntelliJ IDEA.
  User: 862982795
  Date: 2021/09/03
  Time: 15:25
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <%
        pageContext.setAttribute("APP_PATH", request.getContextPath());
    %>
    <!-- web路径：
    不以/开始的相对路径，找资源，以当前资源的路径为基准，经常容易出问题。
    以/开始的相对路径，找资源，以服务器的路径为标准(http://localhost:3306)；需要加上项目名
            http://localhost:3306/crud
     -->
    <%--引入jQuery--%>
    <script type="text/javascript" src="${APP_PATH}/static/bootstrap-3.4.1-dist/js/jquery-1.12.4.js"></script>
    <!--引入样式-->
    <link href="${APP_PATH}/static/bootstrap-3.4.1-dist/css/bootstrap.min.css" rel="stylesheet"/>
    <script src="${APP_PATH}/static/bootstrap-3.4.1-dist/js/bootstrap.min.js"></script>
    <title>Title</title>
</head>
<body>
<%--搭建显示页面--%>
<div class="container">
    <%--标题--%>
    <div class="row">
        <div class="col-md-12">
            <h1>在线通讯录</h1>
        </div>
    </div>
    <%--按钮--%>
    <div class="row">

        <div class="col-md-10 col-md-offset-3">
            <%--<button class="btn btn-primary">新增</button>--%>
            <%--<button class="btn btn-danger">删除</button>--%>
            <form action="${pageContext.request.contextPath}/getContacts" method="get">
                <table>
                    <th>查找联系人:</th>
                    <td>
                        <input type="text" name="cname" value="${contactExample.cname}">
                    </td>
                    <td>
                        <button onclick="btnQ();" id="btnQ" class="btn btn-primary col-md-offset-10">查找
                        </button>
                    </td>
                    <td>
                        <button type="button" onclick="window.location.href='/toAdd'"
                                class="btn btn-primary col-md-offset-10">添加联系人
                        </button>
                    </td>

                </table>
            </form>


        </div>
    </div>
    <%--	显示表格数--%>
    <div class="row">
        <div class="col-md-12">
            <table class="table table-hover">
                <tr style="background-color:yellow;">
                    <th>序号</th>
                    <th>姓名</th>
                    <th>手机</th>
                    <th>QQ</th>
                    <th>地址</th>
                </tr>
                <c:forEach var="contact" items="${pageInfo.list}" varStatus="status">
                    <tr <c:if test="${status.index % 2== 1 }">style="background-color:rgb(219,241,212);"</c:if>>
                        <th>${contact.id }</th>
                        <th><a href="${pageContext.request.contextPath}/toUpdate?id=${contact.id}">${contact.cname }</a>
                        </th>
                        <th>${contact.mobile}</th>
                        <th>${contact.email }</th>
                        <th>${contact.address}</th>
                    </tr>
                </c:forEach>
            </table>
        </div>
    </div>

    <%--	显示分页信息--%>
    <div class="row">
        <!--分页文字信息  -->
        <div class="col-md-6">当前 ${pageInfo.pageNum }页,总${pageInfo.pages }
            页,总 ${pageInfo.total } 条记录
        </div>
        <!-- 分页条信息 -->
        <div class="col-md-6">
            <nav aria-label="Page navigation">
                <ul class="pagination">
                    <li>
                        <a href="${APP_PATH}/getContacts?pageNum=1">首页</a>
                    </li>
                    <c:if test="${pageInfo.hasPreviousPage}">
                        <li>
                            <a href="${APP_PATH}/getContacts?pageNum=${pageInfo.pageNum-1}" aria-label="Previous">
                                <span aria-hidden="true">&laquo;</span>
                            </a>
                        </li>
                    </c:if>

                    <c:forEach var="page_Num" items="${pageInfo.navigatepageNums}">
                        <c:if test="${page_Num==pageInfo.pageNum}">
                            <li class="active"><a href="#">${page_Num}</a></li>
                        </c:if>
                        <c:if test="${page_Num!=pageInfo.pageNum}">
                            <li><a href="${APP_PATH}/getContacts?pageNum=${page_Num}">${page_Num}</a></li>
                        </c:if>
                    </c:forEach>

                    <c:if test="${pageInfo.hasNextPage}">
                        <li>
                            <a href="${APP_PATH}/getContacts?pageNum=${pageInfo.pageNum+1}" aria-label="Previous">
                                <span aria-hidden="true">&raquo;</span>
                            </a>
                        </li>
                    </c:if>

                    <li>
                        <a href="${APP_PATH}/getContacts?pageNum=${pageInfo.pages}">末页</a>
                    </li>
                </ul>
            </nav>
        </div>
    </div>
    <%----%>

</div>
<%----%>

<script>
    $(function () {
        // $("#btnQ").click(function () {
        //     alert("btnQ");
        //     $("form").submit();
        // });

        btnQ = function () {
            $("#btnQ").click(function () {
                $("form").submit();
            });
        }

    });
</script>
</body>
</html>
